import QtQuick

//根据角色移动方位或摄像机朝向计算出一个角色朝向

Item{
    id:root

    enum Policy
    {
        BackToCamera,
        FaceToMovement
    }

    property int policy:CharacterDirectionController.FaceToMovement
    property real cameraDirection//摄像机朝向
    property vector3d movement//角色移动方位

    property real characterDirection//角色朝向

    function update(){
        if(policy === CharacterDirectionController.BackToCamera)
        {
            characterDirection = cameraDirection
        }
        else if(policy === CharacterDirectionController.FaceToMovement)
        {
            if(movement.x !==0 || movement.z !== 0)
            {
                characterDirection = Math.atan2(movement.x,movement.z) * 180 / Math.PI
            }
        }
    }

    onCameraDirectionChanged: update()
    onMovementChanged: update()
    onPolicyChanged: update()
}
